package com.easybuilder.common.utils;

import java.util.Random;

/**
 * 部门工具类
 *
 * @author 张兴帅
 * @projectName easy-builder
 * @packageNmae com.easybuilder.common.utils
 * @fileNmae DeptUtil
 * @date 2023-5-16
 * @copyright 华能信息技术有限公司
 * @since 0.0.1
 */
public class DeptUtil {
    private static int MIN_CHAR = 65; //A
    private static int MAX_CHAR = 90; //Z
    private static int LETTER_LEN = 2; //字母长度
    private static int NUMBER_LEN = 2; //数字长度

    /** 生成组织编码 **/
    public static String buildOrgCode() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < LETTER_LEN; i++) {
             sb.append(getRandomLetter());
        }
        for (int i = 0; i < NUMBER_LEN; i++) {
            sb.append(getRandomNum());
        }
        return sb.toString();
    }

    public static void main(String[] args) {

        String code = buildOrgCode();
        int count = 0;
        while (true){
            String code2 = buildOrgCode();
            count++;
            if (code.equals(code2)) {
                break;
            }
        }
        System.out.println("出现重复次数："+ count);

    }

    /** 随机获取一位大写字母 **/
    private static String getRandomLetter(){
        Random random = new Random();
        int r = random.nextInt(27);
        return String.valueOf((char) (r+MIN_CHAR));
    }

    /** 随机获取一位0-9的数字**/
    private static int getRandomNum(){
        Random random = new Random();
        return random.nextInt(9);
    }

}